﻿'         This file is Copyright © 2008-2012 Billy O'Neal and Aommaster
'                            All rights reserved.
'
' This file is released under the 2-Clause BSD license, included in LICENSE.TXT
'                           and on the MHWT website
Imports System.Reflection
Imports System.Runtime.Serialization

<System.Serializable()> Friend Class GlobalOptions
    Private defaultsavefolderinternal As String
    Private helperHandleInternal As String
    Private signatureInternal As String
    Private linksInternal As String
    Private emphasisInternal As String
    Private hEmphasisInternal As String
    Private noteInternal As String
    Private unimportantInternal As String
    Private greetingInternal As String
    Private safeheaderInternal As String
    Private logformInternal As String
    Private logwaitInternal As String
    Private logStaleInternal As String
    Private logResolvedInternal As String
    Private fullmodekeyinternal As String
    Private makebackupsinternal As Boolean
    Private backupdaysinternal As Integer

    Public Delegate Sub Generic()
    <System.NonSerialized()> Private mNonSerializableHandlers As New List(Of Generic)
    Private mSerializableHandlers As New List(Of Generic)
    Public Custom Event Modified As Generic
        AddHandler(ByVal value As Generic)
            If value.Target.GetType.IsSerializable Then
                mSerializableHandlers.Add(value)
            Else
                If mNonSerializableHandlers Is Nothing Then
                    mNonSerializableHandlers = New List(Of Generic)
                End If
                mNonSerializableHandlers.Add(value)
            End If
        End AddHandler
        RemoveHandler(ByVal value As Generic)
            If value.Target.GetType.IsSerializable Then
                mSerializableHandlers.Remove(value)
            Else
                mNonSerializableHandlers.Remove(value)
            End If
        End RemoveHandler
        RaiseEvent()
            Dim temp As New List(Of Generic)
            temp.AddRange(mNonSerializableHandlers)
            For Each item As Generic In temp
                item.Invoke()
            Next
            temp.Clear()
            temp.AddRange(mSerializableHandlers)
            For Each item As Generic In temp
                item.Invoke()
            Next
            temp.Clear()
        End RaiseEvent
    End Event
    Public Sub reset()
        helperHandle = " "
        signature = "[helperhandle]"
        links = "[url=<target>]<text>[/url]"
        emphasis = "[b]<text>[/b]"
        hEmphasis = "[b][color=red]<text>[/color][/b]"
        note = "[b][color=red]Note: [/color][/b]<text>"
        unimportant = "[i][indent]<text>[/indent][/i]"
        greeting = "Hello, [b][username][/b]."
        safeheader = "[b]Before we begin, you should save these instructions in Notepad to your desktop, or print them, for easy reference. Much of our fix will be done in Safe mode, and you will be unable to access this thread at that time. If you have questions at any point, or are unsure of the instructions, feel free to post here and ask for clarification before proceeding.[/b]"
        logform = "[color=red][b]In your next reply, please include the following:<list>[/b][/color]"
        logwait = "Thanks for posting your log. Logs take a while to process due to intensive research that must be done. Please give me some time to look over your logs and I will post back soon :)"
        logStale = "Due to lack of feedback, this topic has been closed. If you need this topic reopened, please contact a staff member with address of this thread. This applies only to the original topic starter. Everyone else please begin a New Topic."
        logResolved = "Since your problem appears to be resolved, this thread will now be closed. If you need this topic reopened, please contact a member of the HJT Team and we will reopen it for you. Include the address of this thread in your request. If you should have a new issue, please start a new topic. This applies only to the original topic starter. Everyone else please begin a New Topic."
    End Sub
    Sub New()
        reset()
    End Sub
    Public Property defaultsavefolder() As String
        Get
            Return defaultsavefolderinternal
        End Get
        Set(ByVal value As String)
            If value <> defaultsavefolderinternal Then
                defaultsavefolderinternal = value
                RaiseEvent Modified()
            End If
        End Set
    End Property
    Public Property fullmodekey() As String
        Get
            Return fullmodekeyinternal
        End Get
        Set(ByVal value As String)
            If value <> fullmodekeyinternal Then
                fullmodekeyinternal = value
                RaiseEvent Modified()
            End If
        End Set
    End Property
    Public Property helperHandle() As String
        Get
            Return helperHandleInternal
        End Get
        Set(ByVal value As String)
            If value <> helperHandleInternal Then
                helperHandleInternal = value
                RaiseEvent Modified()
            End If
        End Set
    End Property
    Public Property signature() As String
        Get
            Return signatureInternal
        End Get
        Set(ByVal value As String)
            If value <> signatureInternal Then
                signatureInternal = value
                RaiseEvent Modified()
            End If
        End Set
    End Property
    Public Property links() As String
        Get
            Return linksInternal
        End Get
        Set(ByVal value As String)
            If value <> linksInternal Then
                linksInternal = value
                RaiseEvent Modified()
            End If
        End Set
    End Property
    Public Property emphasis() As String
        Get
            Return emphasisInternal
        End Get
        Set(ByVal value As String)
            If value <> emphasisInternal Then
                emphasisInternal = value
                RaiseEvent Modified()
            End If
        End Set
    End Property
    Public Property hEmphasis() As String
        Get
            Return hEmphasisInternal
        End Get
        Set(ByVal value As String)
            If value <> hEmphasisInternal Then
                hEmphasisInternal = value
                RaiseEvent Modified()
            End If
        End Set
    End Property
    Public Property note() As String
        Get
            Return noteInternal
        End Get
        Set(ByVal value As String)
            If value <> noteInternal Then
                noteInternal = value
                RaiseEvent Modified()
            End If
        End Set
    End Property
    Public Property unimportant() As String
        Get
            Return unimportantInternal
        End Get
        Set(ByVal value As String)
            If value <> unimportantInternal Then
                unimportantInternal = value
                RaiseEvent Modified()
            End If
        End Set
    End Property
    Public Property greeting() As String
        Get
            Return greetingInternal
        End Get
        Set(ByVal value As String)
            If value <> greetingInternal Then
                greetingInternal = value
                RaiseEvent Modified()
            End If
        End Set
    End Property
    Public Property safeheader() As String
        Get
            Return safeheaderInternal
        End Get
        Set(ByVal value As String)
            If value <> safeheaderInternal Then
                safeheaderInternal = value
                RaiseEvent Modified()
            End If
        End Set
    End Property
    Public Property logwait() As String
        Get
            Return logwaitInternal
        End Get
        Set(ByVal value As String)
            If value <> logwaitInternal Then
                logwaitInternal = value
                RaiseEvent Modified()
            End If
        End Set
    End Property
    Public Property logStale() As String
        Get
            Return logStaleInternal
        End Get
        Set(ByVal value As String)
            If value <> logStaleInternal Then
                logStaleInternal = value
                RaiseEvent Modified()
            End If
        End Set
    End Property
    Public Property logResolved() As String
        Get
            Return logResolvedInternal
        End Get
        Set(ByVal value As String)
            If value <> logResolvedInternal Then
                logResolvedInternal = value
                RaiseEvent Modified()
            End If
        End Set
    End Property

    Public Property logform() As String
        Get
            Return logformInternal
        End Get
        Set(ByVal value As String)
            If value <> logformInternal Then
                logformInternal = value
                RaiseEvent Modified()
            End If
        End Set
    End Property

    Public Property makebackups As Boolean
        Get
            Return makebackupsinternal
        End Get
        Set(ByVal value As Boolean)
            If value <> makebackupsinternal Then
                makebackupsinternal = value
                RaiseEvent Modified()
            End If
        End Set
    End Property

    Public Property backupdays As Integer
        Get
            Return backupdaysinternal
        End Get
        Set(ByVal value As Integer)
            If value <> backupdaysinternal Then
                backupdaysinternal = value
                RaiseEvent Modified()
            End If
        End Set
    End Property
    <OnDeserialized()> Private Sub OnDeSerialized(ByVal context As StreamingContext)
        mNonSerializableHandlers = New List(Of Generic)
        mSerializableHandlers = New List(Of Generic)
    End Sub
End Class
